<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div id="test"></div>

  <script src="./js/react.development.js"></script>
  <script src="./js/react-dom.development.js"></script>
  <script src="./js/babel.min.js"></script>
  <!-- 引入prop-types对组件标签的属性进行限制，react16以前是放在react核心库上面，之后的版本独立分割出去，减小核心库的大小 -->
  <script src="./js/prop-types.js"></script>
  <script type="text/babel">
    class Person extends React.Component {
      render() {
        console.log(this)
        const { name, age, sex } = this.props
        return (
          <ul>
            <li>{name}</li>
            <li>{age}</li>
            <li>{sex}</li>
          </ul>
        )
      }
    }

    // 类型限制
    Person.propTypes = {
      name: PropTypes.string.isRequired, // 限制当前属性类型为字符串，且必传
      age: PropTypes.number,
      speak: PropTypes.func // 注意函数的限制
    }

    // 默认值
    Person.defaultProps = {
      sex: '未知', // 当前属性如果没有传递，则赋予一个默认值
    }


    const p = { name: 'zs', age: 20, sex: 'female' }
    function speak() {
      console.log('speak')
    }
    ReactDOM.render(<Person {...p} speak={speak} />, document.getElementById('test'));
  </script>

</body>

</html>